﻿
@helper RenderPrice(decimal? price)
{
    if(price == null){
        <span class="price">---</span>   
        return;
    }
    
    var priceVal = price.Value;
    var isBig = price >= 5;
    var priceStr = isBig?priceVal.ToString("N1"): priceVal.ToString("N4");
    
    <span class="price @(isBig?"big": "")">@priceStr</span>
}

@helper PriceDifference(decimal? initialPrice, decimal? currentPrice, decimal hugeDiffThreshold, bool moreIsBetter)
{
    if(initialPrice == null || initialPrice == 0m || currentPrice == null){
        <span class="price-diff"></span>
        return;
    }

    var diff = (currentPrice.Value - initialPrice.Value) / initialPrice.Value * 100;

    var isPositive = diff > 0 ^ (!moreIsBetter);
    
    var cssClass = isPositive ? "positive" : "negative";
    var huge = isPositive && Math.Abs(diff) >= hugeDiffThreshold ? "huge" : "";
    
    <span class="price-diff @cssClass @huge">@diff.ToString("+0;-0")%</span>
    
}
